package com.example.hello.client.ProgressBar;

import com.example.hello.BootstrapProgressBar;
import com.github.gwtbootstrap.client.ui.base.ProgressBarBase;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.ui.Connect;

@Connect(BootstrapProgressBar.class)
public class BootstrapProgressBarConnector extends AbstractComponentConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapProgressBar.class);
    }

    @Override
    public BootstrapProgressBarState getState() {
        return (BootstrapProgressBarState) super.getState();
    }

    @Override
    public VBootstrapProgressBar getWidget() {
        return (VBootstrapProgressBar) super.getWidget();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapProgressBarState state = getState();

        VBootstrapProgressBar progressBar = getWidget();

        progressBar.setActive(state.isActive());
        progressBar.setColor(ProgressBarBase.Color.valueOf(state.getColor()));
        progressBar.setPercent(state.getPercent());
        progressBar.setText(state.getText());
        progressBar.setTitle(state.getTitle());
        progressBar.setType(ProgressBarBase.Style.valueOf(state.getType()));
    }

}